{% extends 'backend/subpage/backBase.html' %}
{% block crumb_content %}
    <ol class="breadcrumb">
        <li><a href="/main/userManage">后台管理</a></li>
        <li class="active">邮件管理</li>
    </ol>
    <div class="well">
        邮件管理
        {% block action_title %}
            &nbsp;&nbsp;|&nbsp;&nbsp;<span class="text-primary">历史记录</span>
        {% endblock %}
        {% block action_block %}
            <button class="btn btn-info pull-right" onclick="window.location.href='/main/emailManage/address'">地址
            </button>
        {% endblock %}
    </div>
{% endblock %}
{% block backend_content %}
    <div class="backend_info_table">

    </div>
    <div class="pagination-box">

    </div>
    <script>
        $(function () {
            var cur_item = GetQueryString("per_page") || 15, page = GetQueryString("page") || 1;//配置一页所显示的数据总数以及默认显示为第一页
            $("#body-content").delegate(".showPageItemsBox select", "change", function () {
                cur_item = $(this).val();
                window.location.href = "/main/emailManage?page=" + page + "&per_page=" + cur_item;
            });
            loadAllEmails();
            function loadAllEmails() {
                ajaxRequestJson("GET", "/main/emailHistory?page=" + page + "&per_page=" + cur_item, {}, function (data) {
                    if (data.code === 0) {
                        var str = '';
                        if (data.data.length === 0) {
                            $(".backend_info_table").html("<h4 class='text-center'>暂无邮件信息</h4>");
                        } else {
                            str += '<table class="table table-bordered"><thead><tr>' +
                                '<th>序号</th>' +
                                '<th>收件地址</th>' +
                                '<th>时间</th>' +
                                '</tr></thead>';
                            for (var i = 0; i < data.data.length; i++) {
                                var item = data.data[i];
                                str += '<tr><td>' + (i + 1) + '</td><td>' + (item.address || "暂无") + '</td><td>' + item.time + '</td></tr>';
                            }
                            str += '</table>';
                            $(".backend_info_table").html(str);
                            loadPaginator("/main/emailManage", cur_item, ".pagination-box", data, [15, 20, 30]);
                        }
                    } else {
                        swal("糟糕!", data.msg, "error");
                    }
                }, function (error) {
                    swal("糟糕!", "请求失败！", "error");
                });
            }
        });
    </script>
{% endblock %}
